//菜品设置数据存放
import http from '../../../http/http'
import * as url from '../../../api/lypApi'
const state = {
  positionTableData:[],
  token:sessionStorage.getItem('token') || undefined
};
const actions = {
  getPositionData({commit}){
    return http({
      url:`/lypApi${url.GETPOSITION}`,
      method:"post",
      data:{
        "pageSize": 3,
      }
    }).then(res=>{
      console.log(res)
      this.positionTableData=res.data.list
      // console.log(this.positiontableData)
      commit('addPositionData',res.data.list)
    }).catch(err=>{
      console.log(err)
    })
  },
  deletePositionData({commit},obj){
    console.log(obj)
    let delData=this.staffTableData.filter(item=> item.id!=obj.id)
    this.positionTableData=delData
    let data=this.positionTableData.filter(item=> item.id==obj.id)
    http({
      url:`/lypApi${url.DELPOSITION}`,
      method:'post',
      data:{
        "id":obj.id
      },
    }).then(res=>{
      console.log(res)
    }).catch(err=>{
      console.log(err)
    })
    commit('addPositionData',delData)
  },
  selectPositionData({commit},obj){
    console.log(obj)
    console.log(typeof obj)
    // return dispatch('getData').then(() => {
    //   // commit('someOtherMutation')
    // })
    // let selectData=[]
    // if(obj){
    //   this.positionTableData.forEach((item)=>{
    //     if (item[obj[0]]==obj[1]){
    //       console.log(item)
    //       selectData.push(item)
    //     }
    //   })
    // }
    return http({
      url:`/lypApi${url.SELECTPOSITION}`,
      method:"post",
      data:{
        "name": obj,
      }
    })
  }
};
const mutations = {
  addPositionData(state,obj){
    state.positionTableData = obj
    console.log(this.positionTableData)
  }
}
const  getters= {

};
export default {
  state,
  actions,
  mutations,
  getters
}
